package wypozyczalnia.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import wypozyczalnia.domain.Hire;
import wypozyczalnia.forms.RentForm;
import wypozyczalnia.service.HireService;

@Controller
@RequestMapping(value = "/adminRaport/*")
public class AdminRaportController {

	private final Logger logger = Logger.getLogger(ProfileController.class);
	@Autowired
	HireService hireService;

	@RequestMapping(value = "adminRaportList.do")
	public String list(HttpSession session, HttpServletResponse response,
			HttpServletRequest request, Model model) {
		List<Hire> hires = hireService.getHiresForRaport();
		 model.addAttribute("hires", hires);
		return "adminRaportList";
	}
	
	@RequestMapping(value = "adminRaportDetails.do" , method = RequestMethod.POST)
	public String details(HttpSession session, HttpServletResponse response,
			HttpServletRequest request, Model model,RentForm rentForm) {
		
		 Hire hire = hireService.getHireById(rentForm.getId());
		 model.addAttribute("hire", hire);
		 
		return "adminRaportDetails";
	}
}
